﻿using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;
using EventPlanner.Models;
using PagedList;
using EventPlanner.Authorization;
using System.Web.Security;
using System.Collections.Generic;

namespace EventPlanner.Controllers
{
    public class HomeController : Controller
    {
        private DropCreateDatabaseIfModelChanges<EventPlannerContext> c = new DropCreateDatabaseIfModelChanges<EventPlannerContext>();
        private IEventPlannerContext _db = new EventPlannerContext();

        public HomeController(IEventPlannerContext db) { _db = db; }

        private IEnumerable<Evento> ProximosEventos(int dias)
        {
            var hoy = DateTime.Today;
            var limite = hoy.AddDays(dias);
            var eventos = from e in _db.Evento where e.Fecha > hoy && e.Fecha < limite orderby e.Fecha select e;
            return eventos;
        }

        private IEnumerable<Evento> ProximosEventosCant(int cant)
        {
            var eventos = (from e in _db.Evento where e.Fecha >= DateTime.Today orderby e.Fecha select e).Take(cant);
            return eventos;
        }
        private IEnumerable<Evento> EventosMes()
        {
            int mes = DateTime.Today.Month;
            var eventos = from e in _db.Evento where e.Fecha.Month == mes orderby e.Fecha select e;
            return eventos;
        }

        public ActionResult Index()

        {
            return View(ProximosEventosCant(6));
        }
    }
}
